<script>
	export default {
		globalData:{
			kyMainColor: "#212c67",
			hasCreatScript: false,
			sysWidth: 0,
			hasOverdue: null ,//token过期flag
			sysInfo: {},
			sysEdition: "" //手机系统版本
		},
		onLaunch:async function() {
			//#ifdef APP-PLUS
			plus.screen.lockOrientation('portrait-primary'); // 强制竖屏
			//#endif
			const that = this;
			const systemInfo = uni.getSystemInfoSync();
			let sysWidth =  systemInfo.windowWidth;
			getApp().globalData.sysWidth = sysWidth;
			getApp().globalData.sysInfo = systemInfo;
			getApp().globalData.sysEdition = systemInfo.system.split('.')[0];
			// 设置token
			uni.getStorage({
				key:'powerToken',
				success(res){
					that.$store.commit('set_token',res.data);
				},
				fail(err) {
					that.$store.commit('set_token',"");
				}
			})
			try{
				const setbaseURL = await this.setbaseURL();
				this.$store.dispatch("set_appConfigAction");
			}catch(err){
				uni.showModal({
					title: "提示",
					content: "暂未设置API地址，请先设置API地址",
					showCancel: true,
					success(res) {
						if(res.confirm){
							uni.navigateTo({
								url:'/pages/changeUrl/index'
							})
						}
						if(res.cancel){
							
						}
					}
				})
			}
			// 设置
			// #ifdef APP-PLUS
			this.getNet().then((res)=>{
			}).catch((err)=>{})
			// #endif
		},
		methods:{
			setbaseURL(){
				const that = this;
				return new Promise((resolve,reject)=>{
					uni.getStorage({
						key:'baseUrl',
						success(res){
							that.$store.commit('set_baseUrl',res.data);
							resolve(res)
							if(!res.data){
								uni.showModal({
									title:"提示",
									content:"暂未设置API地址，请先设置API地址",
									showCancel:true,
									success(res) {
										if(res.confirm){
											uni.navigateTo({
												url:'/pages/changeUrl/index'
											})
										}
										if(res.cancel){
										}
									}
								})
							}
						},
						fail(err) {
							reject(err)
						}
					})
				})
			},
			// 获取网络状态
			getNet(){
				return new Promise((resolve,reject)=>{
					uni.getNetworkType({
					    success: function (res) {
								resolve(res);
					    },
							fail:function(err){
								reject(err)
							}
					});
				})
			},
			// 获取app配置项
			getAppConfig(){
				this.$http.httpRequest({
					url: this.$api.config,
					methods: "get"
				}).then((res)=>{
					if(!res){
						return uni.showToast({
							title:'服务器请求失败',
							icon:'none'
						})
					}
					this.$store.commit("set_appConfig",res.data.config)
				}).catch((err)=>{
					
				})
			}
		},
		onShow: function() {

		},
		onHide: function() {
			
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
	*{
		box-sizing: border-box;
		margin: 0;
		padding: 0;
	}
	.mar-px20{
		margin: 20rpx;
		background: #fff;
	}
	.open-switch{
		color: #00d600;
	}
	.close-switch{
		color: #888;
	}
	view,text{
		box-sizing: inherit;
		color: inherit;
		font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
	}
	page{
		width: 100%;
		min-height: 100%;
		// #ifdef APP-PLUS
		background-image: url('/static/images/bg.png');
		background-repeat: no-repeat;
		background-attachment: fixed;
		background-size: contain;
		background-position: 50% -1rpx;
		// #endif
	}
	// #ifdef H5
	uni-page{
		background-image: url('/static/images/bg.png');
		background-repeat: no-repeat;
		background-attachment: fixed;
		background-size: contain;
		background-position: 50% -1rpx;
	}
	// #endif

	$contain-main-boxPaddingTop:calc(150rpx - var(--status-bar-height));
	.status_bar{
		height: var(--status-bar-height);
	}
	.contain-main-box{
		padding-top: 150rpx;
	}
	.contain-box,.main-bg{
		width: 100%;
		min-height: calc( 100vh - 300rpx );
		position: relative;
		font-size: 30rpx;
	}
		.clearFix::after{
			content: "";height: 0;clear: both;display: block;
		}
		.text-gray{
			color: #888;
		}
		.text-level0{
			color: $level0;
		}
		.text-level1{
			color: $level1;
		}
		.text-level2{
			color: $level2;
		}
		.text-level3{
			color: $level3;
		}
		.text-level4{
			color: $level4;
		}
		// 告警背景颜色
		.alarmLevel0{
			background-color: $level0;
		}
		.alarmLevel1{
			background-color: $level1;
		}
		.alarmLevel2{
			background-color: $level2;
		}
		.alarmLevel3{
			background-color: $level3;
		}
		.alarmLevel4{
			background-color: $level4;
		}
		.tree-alarm{
			width: 30rpx;
			height: 30rpx;
			text-align: center;
			line-height: 30rpx;
			font-size: 26rpx;
			color: #fff;
			display: block;
			border-radius: 50%;
			margin-left: 15rpx;
		}
		.tree-alarm1{
			background-color: $level1;
		}
		.tree-alarm2{
			background-color: $level2;
		}
		.tree-alarm3{
			background-color: $level3;
		}
		.tree-alarm4{
			background-color: $level4;
		}
		.text-center{
			text-align: center;
		}
		.float-block{
			float: left;
		}
		.wrap{
			background: rgba(255,255,255,0.8);
		}
		.box-shadow{
			box-shadow: 0 0 30rpx rgba(33,44,103,0.3);
		}
.float-block{
    float: left;
}
.wrap{
    background: rgba(255,255,255,0.8);
}
.box-shadow{
    box-shadow: 0 0 30rpx rgba(33,44,103,0.3);
}
.red-level4::after{
    position: absolute;top: 5rpx;right: -5rpx;
    width: 22rpx;height: 22rpx;border-radius: 50%;
    background: $level4;content: " ";
}
.orange-level3::after{
    background: $level3;position: absolute;top: 5rpx;right: -5rpx;
    width: 22rpx;height: 22rpx;border-radius: 50%;content: " ";
}
.blue-level1::after{
    position: absolute;top: 5rpx;right: -5rpx;
    width: 22rpx;height: 22rpx;border-radius: 50%;
    background: $level1;content: " ";
}
.yellow-level2::after{
    position: absolute;top: 5rpx;right: -5rpx;
    width: 22rpx;height: 22rpx;border-radius: 50%;
    background: $level2;content: " ";
}
.fx-pao{
    position: absolute;content:" ";
    right: 10rpx;top: 10rpx;width: 65rpx;height: 57rpx;
    // background: url($baseImg + '/icon/pao.png') no-repeat;
		background-repeat: no-repeat;
    background-size: contain;font-size: 26rpx;color: #fff;text-align: center;line-height: 47rpx;
}
.fx-pao-red{
    position: absolute;content:" ";
    right: 10rpx;top: 10rpx;width: 65rpx;height: 57rpx;
    background-repeat: no-repeat;
    background-size: contain;font-size: 26rpx;color: #fff;text-align: center;line-height: 47rpx;
}
.fx-pao-orange{
    position: absolute;content:" ";
    right: 10rpx;top: 10rpx;width: 65rpx;height: 57rpx;
    background-repeat: no-repeat;
    background-size: contain;font-size: 26rpx;color: #fff;text-align: center;line-height: 47rpx;
}
.fx-pao-yellow{
    position: absolute;content:" ";
    right: 10rpx;top: 10rpx;width: 65rpx;height: 57rpx;
    background-repeat: no-repeat;
    background-size: contain;font-size: 26rpx;color: #fff;text-align: center;line-height: 47rpx;
}
.fx-pao-blue{
    position: absolute;content:" ";
    right: 10rpx;top: 10rpx;width: 65rpx;height: 57rpx;
    background-repeat: no-repeat;
    background-size: contain;font-size: 26rpx;color: #fff;text-align: center;line-height: 47rpx;
}
// .fx-red{
// 	background-image: url($baseImg + '/icon/pao.png');
// }
// .fx-orange{
// 	background-image: url($baseImg + '/icon/orange.png');
// }
// .fx-yellow{
//   background-image: url($baseImg + '/icon/yellow.png');
// }
// .fx-blue{
//    background-image: url($baseImg+'/icon/blue.png');
// }
	// 配电柜 10
	// .pdg{
	// 	background-image: url($baseImg + '/icon/box.png');
	// }
	// .ups{
	// 	background-image: url($baseImg + '/icon/ups.png');
	// } 
	// // 单项ups 22
	// .ups-dx{
	// 	background-image: url($baseImg + '/icon/ups.png');
	// }
	// // 三项ups 11
	// .ups-sx{
	// 	background-image: url($baseImg + '/icon/ups-sx.png');
	// }
	// // 温湿度 0
	// .wsd{
	// 	background-image: url($baseImg + '/icon/wsd.png');
	// }
	// // 漏水 4
	// .ls{
	// 	background-image: url($baseImg + '/icon/ls.png');
	// }
	// // 精密空调 5
	// .jmkt{
	// 	background-image: url($baseImg + '/icon/jmkt.png');
	// }
	// // 普通空调 6
	// .ptkt{
	// 	background-image: url($baseImg + '/icon/ptkt.png');
	// }
	// // 烟感 1
	// .yg{
	// 	background-image: url($baseImg + '/icon/yg.png');
	// }
	// // 视频
	// .sp{
	// 	background-image: url($baseImg + '/icon/sp.png');
	// }
	// // 门禁
	// .mj{
	// 	background-image: url($baseImg + '/icon/mj.png');
	// }
	// // 红外传感器 23
	// .hw{
	// 	background-image: url($baseImg + '/icon/hw.png');
	// }
	// // 红外报警主机 14
	// .hw-bgzj{
	// 	background-image: url($baseImg + '/icon/hw-bgzj.png');
	// }
	// // 蓄电池 电池组 - 12
	// .xdc{
	// 	background-image: url($baseImg + '/icon/dcz.png');
	// }
	// // 直流开关电源 29
	// .zlkgdy{
	// 	background-image: url($baseImg + '/icon/zlkgdy.png');
	// }
	// // 普通新风机 -7  
	// .xfj-pt{
	// 	background-image: url($baseImg + '/icon/xfj-pt.png');
	// }
	// // 智能新风机 - 24
	// .xfj-zn{
	// 	background-image: url($baseImg + '/icon/xfj-zn.png');
	// }
	// // 照明控制器 - 8
	// .zmkzq{
	// 	background-image: url($baseImg + '/icon/zmkzq.png');
	// }
	// // 消防主机
	// .xfzj{
	// 	background-image: url($baseImg + '/icon/xfzj.png');
	// }
</style>
